package com.hyc.myvideo.data.adapter.my.attention;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.acmenxd.toaster.Toaster;
import com.hyc.myvideo.R;
import com.hyc.myvideo.data.adapter.base.BaseListAdapter;
import com.hyc.myvideo.data.api.model.Attention;
import com.hyc.myvideo.utils.imguitl.ImgUitl;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 我的关注适配器
 * @author gyb
 * @version 1.0
 * @created 2017/07/18
 */
public class AttentionAdapter extends BaseListAdapter<Attention> {
    public AttentionAdapter(Context context, List<Attention> objects) {
        super(context, objects);
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            if (getItemViewType(position) == 0) {
                holder = new ViewHolder();
                //无数据展示
                convertView = inflater.inflate(R.layout.adapter_itme_no, parent, false);
                holder.noDataRootLayout = (LinearLayout) convertView.findViewById(R.id.r_no_id);
            } else {
                convertView = inflater.inflate(R.layout.activity_adapter_attention_item, parent, false);
                holder = new ViewHolder(convertView);
            }
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (hasNoData) {
            AbsListView.LayoutParams lp = new AbsListView.LayoutParams(getScreenWidth(), getScreenHeight() * 2 / 3);
            holder.noDataRootLayout.setLayoutParams(lp);
        } else {
            Attention attention = mDataList.get(position);
            ImgUitl.setImg(attention.getDirect_cover(), holder.imgCover, ImgUitl.dip2px(mContext,60),ImgUitl.dip2px(mContext,60));
            //是否直播
            setLiveStatus(holder,attention);
            holder.textViewTitle.setText(String.format(mContext.getString(R.string.huc_my_course), attention.getDirect_name()));
            holder.textViewContent.setText(String.format(mContext.getString(R.string.huc_my_lecturer),attention.getAnchor_name()));
        }
        return convertView;
    }

    public static class ViewHolder {
        public ViewHolder() {
        }
        public ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
        LinearLayout noDataRootLayout;
        //图片
        @BindView(R.id.attention_img_cover)
        ImageView imgCover;
        //标题
        @BindView(R.id.attention_t_title)
        TextView textViewTitle;
        //内容
        @BindView(R.id.attention_t_content)
        TextView textViewContent;
        //状态
        @BindView(R.id.attention_t_status)
        TextView textViewStatus;
        @BindView(R.id.attention_watch)
        //观看直播
        Button buttonWatch;
    }

    /****
     * 设置直播状态
     * @param holder
     * @param comment
     */
    private void setLiveStatus(ViewHolder holder,final Attention comment){
        //0 未开始，1=正在直播，3=已经结束
        switch(comment.getDirect_hour_state()){
            case 1:
                holder.textViewStatus.setText("正在直播");
                holder.textViewStatus.setBackgroundResource(R.color.color_10alpha_80);
                holder.buttonWatch.setClickable(true);
                holder.buttonWatch.setBackgroundResource(R.drawable.button_shape_35_0);
                holder.buttonWatch.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toaster.show("观看直播");
                    }
                });
                break;
            case 3:
                holder.textViewStatus.setText("已结束");
                holder.textViewStatus.setBackgroundResource(R.color.color_9alpha_80);
                holder.buttonWatch.setClickable(true);
                holder.buttonWatch.setBackgroundResource(R.drawable.button_shape_35);
                holder.buttonWatch.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toaster.show("观看录播");
                    }
                });
                break;
            default:
                break;
        }
    }



}
